// Promise.then.catch
<template>
  <div>
    <prism language="javascript">
      var p = new Promise((resolve, reject) => {
      //箭头函数
      resolve("data from p"); //成功信息
      });
      p.then(data => {
      console.log(data);
      return "hello" + data;
      })
      .then(function(data) {
      console.log(data);
      //  return("hello"+data);
      return new Promise((resolve, reject) => {
      resolve("hello" + data);
      });
      })
      .then(function(data) {
      setTimeout(console.log, 3000, data); //3s之后执行
      })
      .catch(error => {
      console.log(error);
      }); //catch()可以把每一个then()的所有错误都捕获
    </prism>
    <v-btn
      round
      color="success"
      @click="run"
    >
      RUN
    </v-btn>
  </div>
</template>

<script>
import Prism from "vue-prism-component";
export default {
  components: {
    Prism
  },
  methods: {
    run() {
      var p = new Promise((resolve, reject) => {
        //箭头函数
        resolve("data from p"); //成功信息
      });
      p.then(data => {
        console.log(data);
        return "hello" + data;
      })
        .then(function(data) {
          console.log(data);
          //  return("hello"+data);
          return new Promise((resolve, reject) => {
            resolve("hello" + data);
          });
        })
        .then(function(data) {
          setTimeout(console.log, 3000, data); //3s之后执行
        })
        .catch(error => {
          console.log(error);
        }); //catch()可以把每一个then()的所有错误都捕获
    }
  }
};
</script>